package com.eedi.framework.tenant.service;

import com.eedi.framework.common.enums.CommonStatusEnum;
import com.eedi.framework.common.exception.util.PreconditionsUtils;
import com.eedi.framework.tenant.controller.sys.vo.setup.SysSetupBottomReq;
import com.eedi.framework.tenant.controller.sys.vo.setup.SysSetupBottomResp;
import com.eedi.framework.tenant.controller.sys.vo.setup.SysSetupBottomUpReq;
import com.eedi.framework.tenant.dal.mapper.SysSetupBottomMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.eedi.framework.tenant.enums.SysTenantErrorCodeConstants.SYS_BOTTOM_NOT_EXISTS;

/**
 * 底部设置
 *
 * @author zybourn
 */
@Service
@Slf4j
public class SysSetupBottomServiceImpl implements SysSetupBottomService {
    @Resource
    SysSetupBottomMapper sysSetupBottomMapper;

    @Override
    public void create(SysSetupBottomReq req) {
        sysSetupBottomMapper.insert(req);
    }

    @Override
    public void update(SysSetupBottomUpReq req) {
        SysSetupBottomResp sysSetupBottom = sysSetupBottomMapper.getById(req.getSysSetupBottomId());
        PreconditionsUtils.checkNotNull(sysSetupBottom,SYS_BOTTOM_NOT_EXISTS);
        sysSetupBottomMapper.update(req);
    }

    @Override
    public void enable(String sysSetupBottomId) {
        SysSetupBottomResp sysSetupBottom = sysSetupBottomMapper.getById(sysSetupBottomId);
        PreconditionsUtils.checkNotNull(sysSetupBottom,SYS_BOTTOM_NOT_EXISTS);
        sysSetupBottomMapper.upStatus(sysSetupBottomId, CommonStatusEnum.ENABLE);
    }

    @Override
    public void disable(String sysSetupBottomId) {
        SysSetupBottomResp sysSetupBottom = sysSetupBottomMapper.getById(sysSetupBottomId);
        PreconditionsUtils.checkNotNull(sysSetupBottom,SYS_BOTTOM_NOT_EXISTS);
        sysSetupBottomMapper.upStatus(sysSetupBottomId, CommonStatusEnum.DISABLE);
    }

    @Override
    public List<SysSetupBottomResp> getList() {
        return sysSetupBottomMapper.getList();
    }
}
